<template>
    <span></span>
</template>
<script>
  import {
    addPolyline,
    getCircle,
    getPolygon,
  } from '@/common/js/bdmap'
    export default{
        props:["dataSource"],
        data(){
            return {
                map:null
            }
        },
        created() {
            this.map = this.$store.state.maps.map;

        },
        mounted() {
        //  this._getFenceInfo();
            this.showLocation();
        },
        methods:{
            showLocation(){
                var points = this.dataSource;
                var point = new BMap.Point(points.lng, points.lat);
                var mark = new BMap.Marker(point);
                this.map.addOverlay(mark);
              this.map.panTo(point);
              this.map.setZoom(14);
            },
          _getFenceInfo() {
//            // 出土点
//            this.getCircle(new BMap.Point(121.6780840000, 30.0012300000), 200, "green")
//            //消纳场
//            this.getCircle(new BMap.Point(121.6546330000, 30.0536790000), 500, "orange")
//            let routeList =
//              [{"lng":121.680151,"lat":29.996085},{"lng":121.672677,"lat":30.001965},{"lng":121.680582,"lat":30.010472},{"lng":121.67009,"lat":30.019353},{"lng":121.658879,"lat":30.035988},{"lng":121.665634,"lat":30.03899},{"lng":121.650255,"lat":30.056997},{"lng":121.65543,"lat":30.060247},{"lng":121.65543,"lat":30.060247}]
//            var onLineCoordinates = [];
//            for (let i = 0; i < routeList.length; i++) {
//              // 线上的点
//              let item = routeList[i];
//              let point = new BMap.Point(item.lng, item.lat);
//              onLineCoordinates.push(point);
//            }
//            this.addPolyline(onLineCoordinates)


          },
          // 添加线路覆盖物
         addPolyline(data){
            let polyline = new BMap.Polyline(data);//BMap.Polyline([point1,point2], { strokeColor: "blue", strokeWeight: 4, strokeOpacity: 1, strokeStyle: 'slolid' });
            polyline.setStrokeColor("red");
            polyline.setStrokeWeight(4);
            polyline.setStrokeOpacity(0.6);
            // polyline.setStrokeOpacity(1);
            polyline.setStrokeStyle('solid');
           this.map.addOverlay(polyline);
          },

// 获取圆形覆盖物
        getCircle(point, radius,color){
            // map.clearOverlays();
            if(!color)
              color= "red"
            let circle = new BMap.Circle(point,radius, {strokeColor:color, strokeWeight:3, strokeOpacity:0.8});
          this.map.addOverlay(circle);
            //map.setViewport([point]); // 调整视野
            // map.panTo(point);
            // map.setZoom(14);
          }
        }
    }
</script>
